package cn.edu.sdu.sduhour.controller;

import cn.edu.sdu.sduhour.entity.History;
import cn.edu.sdu.sduhour.mapper.HistoryMapper;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/his")
public class HistoryController {
    @Resource
    HistoryMapper historyMapper;

    //获取所有人的历史记录（管理员）
    @GetMapping("/all")
    public List<History> findAll() {
        return historyMapper.findAll();
    }

    //获取某个人的历史记录
    @PostMapping("/one")
    public List<History> findOne(@RequestBody History history) {
        return historyMapper.findOne(history);
    }

    //添加一条历史记录
    @PostMapping("/add")
    public List<History> addOne(@RequestBody History history) {
        historyMapper.addOne(history);
        return historyMapper.findOne(history);
    }

    //更新一条历史记录
    @PostMapping("/upd")
    public List<History> updOne(@RequestBody History history) {
        historyMapper.updOne(history);
        return historyMapper.findOne(history);
    }

    //删除一条历史记录（管理员）
    @DeleteMapping("/del")
    public String delOne(@RequestBody History history) {
        historyMapper.delOne(history);
        return "success";
    }
}
